package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.login.TsLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"all"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;
	/**
	 * @author WeakMoon
	 * @date 2025/03/09 20:25:44
	 * 提交订单
	 * 接口地址：http://localhost/api/order/orderInfo/submitOrder
	 * 请求方式：POST
	 */
	@TsLogin
	@Operation(summary = "提交订单")
	@PostMapping("/submitOrder")
	public Result submitOrder(@RequestBody @Validated OrderInfoVo orderInfoVo){
		//获取用户信息
		Long userId = AuthContextHolder.getUserId();

		//调用服务层方法
		String orderNo = orderInfoService.submitOrder(orderInfoVo,userId);

		//存储orderNo
		Map<String, Object> map = new HashMap<>();
		map.put("orderNo",orderNo);

		//返回结果数据
		return Result.ok(map);
	}

	/**
	 * @author WeakMoon
	 * @date 2025/03/07 16:59:04
	 * 生成订单详情页
	 * 接口地址：http://localhost/api/order/orderInfo/trade
	 * 请求方式：post
	 */
	@TsLogin
	@Operation(summary = "生成订单详情页")
	@PostMapping("/trade")
	public Result trade(@RequestBody @Validated TradeVo tradeVo){
		//获取用户信息
		Long userId = AuthContextHolder.getUserId();

		//调用服务层方法
		OrderInfoVo orderInfoVo = orderInfoService.trade(tradeVo,userId);

		//返回结果数据
		return Result.ok(orderInfoVo);
	}
}

